﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Ninject;
using Ninject.Syntax;
using JCTimes.DomainModel.Repository;
using JCTimes.EFRepository.RepositoryImpl;
using JCTimes.DomainModel.Entity;
using Ninject.Web.Common;

namespace JCTimes.Portal.Infrastructure
{
    public class NinjectDependencyResolver : IDependencyResolver
    {
        private IKernel kernel;

        public NinjectDependencyResolver()
        {
            kernel = new StandardKernel();
            AddBindings();
        }

        public IKernel Kernel { get { return kernel; } }

        public object GetService(Type serviceType)
        {
            return kernel.TryGet(serviceType);
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return kernel.GetAll(serviceType);
        }

        public IBindingToSyntax<T> Bind<T>()
        {
            return kernel.Bind<T>();
        }

        private void AddBindings()
        {
            Bind<JCTimes.EFRepository.JCTimesDbContext>().ToSelf().InRequestScope();
            Bind<IUserRepository>().To<UserRepository>();
            Bind<IPDARepository>().To<PDARepository>();
            Bind<IFunctionsRepository>().To<FunctionsRepository>();
            Bind<IFunctionRoleRepository>().To<FunctionRoleRepository>();
            Bind<IRoleRepository>().To<RoleRepository>();
            Bind<IViewRepository>().To<ViewRepository>();

            Bind<IExpressClassRepository>().To<ExpressClassRepository>();
            Bind<ILoginLogRepository>().To<LoginLogRepository>();
            Bind<IPDAConnectLogRepository>().To<PDAConnectLogRepository>();
            Bind<IPDAFunctionsRepository>().To<PDAFunctionsRepository>();
            Bind<IPDAUsersFunctionsRepository>().To<PDAUsersFunctionsRepository>();
            Bind<IPDAPDAFunctionsRepository>().To<PDAPDAFunctionsRepository>();
            Bind<IPDAVersionsRepository>().To<PDAVersionsRepository>();
        }
    }
}